<?php defined('BASEPATH') OR exit('No direct script access allowed');
/**
 *
 * @author 		PyroCMS Dev Team
 * @package 	PyroCMS
 * @subpackage 	Contact
 * @category 	Module
 */
class Cip_groups_m extends MY_Model {
	
	public function insert($input = array())
	{
		$this->load->helper('text');
		$id = parent::insert(array(
			'title'=>$input['title'],
			'category_id'=>$input['category_id'],
			'owner_id'=>$input['owner_id'],
			'comment'=>$input['comment'],
			'url'=>$input['url'],
			'note'=>$input['note'],
			'valid'=>$input['valid'],
			'create_date' => time()
		));
		return $id;
	}
	public function update($id, $input)
	{
		return parent::update($id, array(
			'title'=>$input['title'],
			'category_id'=>$input['category_id'],
			'owner_id'=>$input['owner_id'],
			'comment'=>$input['comment'],
			'url'=>$input['url'],
			'note'=>$input['note'],
			'valid'=>$input['valid']
		));
	}
	public function updateDelete($id, $input)
	{
		return parent::update($id, array(
			'title'=>$input['title'],
			'category_id'=>$input['category_id'],
			'owner_id'=>$input['owner_id'],
			'comment'=>$input['comment'],
			'url'=>$input['url'],
			'note'=>$input['note'],
			'valid'=>$input['valid'],
			'deleted'	=> $input['deleted']
		));
	}
	public function getAllGroups($criteria,  $order = 'ASC',$limit){
		return $this->cip_groups_m->select('cip_groups.*')
						->join('cip_owners o','cip_groups.owner_id = o.id')
						->join('cip_categories c','cip_groups.category_id = c.id')
						->where('cip_groups.deleted', 0)
						->order_by($criteria, $order)
						->limit($limit)
						->get_all();
	}
	
	/**
	 * Callback method for validating the title
	 * @access public
	 * @param string $title The title to validate
	 * @return mixed
	 */
	public function check_title($title = '')
	{
		return parent::count_by('title', $title) > 0;
	}
}